package com.habitreformer.core.task;

import java.util.Date;

import android.util.Log;
import env.Env;
import env.Environmental;

public class TaskImpl implements Task
{
	final static TaskRating DEFAULT_TASK_RATING = TaskRating.UNRATED;
	final static TaskStatus DEFAULT_TASK_STATUS = TaskStatus.UNSTARTED;

	private static Environmental env = Env.getInstance();
	private TaskRating rating;
	private TaskStatus status;
	private Date finishedDate;

	public TaskImpl()
	{
		this.rating = DEFAULT_TASK_RATING;
		this.status = DEFAULT_TASK_STATUS;
	}

	@Override
	public TaskRating getRating()
	{
		return rating;
	}

	@Override
	public TaskStatus getStatus()
	{
		return status;
	}

	@Override
	public void setRating(TaskRating rating)
	{
		this.rating = rating;
	}

	@Override
	public void setStatus(TaskStatus status)
	{
		this.status = status;
	}

	@Override
	public void finishTask(TaskRating rating)
	{
		if (null != rating)
		{
			this.rating = rating;
			finishedDate = env.getDate();
			this.status = TaskStatus.SUCCESSFUL;
		} else
		{
			Log.w("Task", "Null Task Rating! Ignored and keep task as it was.");
		}
	}

	@Override
	public Date getFinishedDate()
	{
		return finishedDate;
	}

	@Override
	public boolean isFinished()
	{
		return TaskStatus.SUCCESSFUL == this.status;
	}

	public static void main(String args[])
	{
		Task task = new TaskImpl();
		System.out.println(task.isFinished());
	}

}
